package br.com.felix.fwt.ui.validation;

import java.util.ArrayList;
import java.util.List;

import br.com.felix.fwt.ui.BaseComponent;
import br.com.felix.fwt.util.Util;

public class EmailValidator extends Validator{

	public EmailValidator(BaseComponent ...components) {
		super(components);
	}

	@Override
	public List<ValidationError> isValid() {
		List<ValidationError> lst = new ArrayList<ValidationError>();
		for (BaseComponent c: getComponents()){
			String value = c.getValue();
			if (!Util.isAValidEmail(value)){
				ValidationError ve = new ValidationError("EmailFormatError");
				ve.setReferences(c.getName());
				lst.add(ve);
			}
		}
		return lst;
	}

}
